var io = require('socket.io-client');
registerCtrl.$injcet = ['$scope', '$location', '$http'];
function registerCtrl($scope, $location, $http) {
    

    $scope.back = function () {
        $location.path('/audit');
    }
    $scope.register = function () {

        var socket = io.connect("ws://10.222.29.156:8888/");
        socket.emit('register', 'merchant register...');


        let isEmpty = false;
        document.querySelectorAll('#registerForm input').forEach(function (value) {
            if (!value.value)
                isEmpty = true;
        })
        if (isEmpty)
            return;

        var merchantForm = document.querySelector('#registerForm');
        var formData = new FormData(merchantForm);
        // for (var pair of formData.entries()) {
        //   console.log(pair[0] + ', ' + pair[1]);
        // }
        $http({
            method: 'POST',
            url: '/o2o/register',
            data: formData,
            headers: {
                'Content-Type': undefined
            }
        }).then(function (response) {
            let data = response.data;
            if (data.error) {
                $scope.error = '用户名被注册！';
                return;
            }
            $location.path('/audit');
        })
    }
}
module.exports = registerCtrl;